<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.11.3.js"></script>
<script type="text/javascript">
function showHint(str)
{
var xmlhttp;
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
	  if(xmlhttp.readyState == 0){
		  alert("readyState=0");
	  }
	  if(xmlhttp.readyState == 1){
		  alert("readyState=1");
	  }
	  if(xmlhttp.readyState == 2){
		  alert("readyState=2");
	  }
	  if(xmlhttp.readyState == 3){
		  alert("readyState=3");
	  }
	  if(xmlhttp.readyState == 4){
		  alert("readyState=4");
	  }
	  if(xmlhttp.status == 200){
		  alert("status=200");
	  }
	  if(xmlhttp.status == 404){
		  alert("status=404");
	  }
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<h3>请在下面的输入框中键入字母（A - Z）：</h3>
<form action=""> 
姓氏：<input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>建议：<span id="txtHint"></span></p> 
</body>
<script>
$(function(){
  var val=$('#txt1').val();
  $('#txt1').on('click',function(){
	     alert(this.value);
	  });
});
</script>
</html>